package com.ruoyi.bzjgl.service.impl;

import com.ruoyi.bzjgl.mapper.IndexMapper;
import com.ruoyi.bzjgl.service.IIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class IndexServiceImpl implements IIndexService {

    @Autowired
    private IndexMapper indexMapper;

    @Override
    public HashMap<String, Object> getAmount(HashMap<String,List<String>> depNames) {
        return indexMapper.getAmount(depNames);
    }

    @Override
    public List<HashMap<String, Object>> getAmountGroupByOrg(HashMap<String,List<String>> depNames) {
        return indexMapper.getAmountGroupByOrg(depNames);
    }

    @Override
    public List<HashMap<String, Object>> getMsBing(HashMap<String,List<String>> depNames) {
        List<HashMap<String,Object>> map = new ArrayList<>();
        HashMap<String, Object> msBing = indexMapper.getMsBing(depNames);
        if(msBing!=null){
            HashMap<String, Object> ms = new HashMap<>();
            ms.put("name","没收占比");
            ms.put("value",msBing.get("mszb")==null?0:msBing.get("mszb"));
            map.add(ms);
            HashMap<String, Object> th = new HashMap<>();
            th.put("name","退回占比");
            th.put("value",msBing.get("thzb")==null?0:msBing.get("thzb"));
            map.add(th);
            HashMap<String, Object> qt = new HashMap<>();
            qt.put("name","未处理占比");
            qt.put("value",msBing.get("qtzb")==null?0:msBing.get("qtzb"));
            map.add(qt);
        }else{
            HashMap<String, Object> qt = new HashMap<>();
            qt.put("name","未处理占比");
            qt.put("value",100);
            map.add(qt);
        }

        return map;
    }

    @Override
    public List<HashMap<String, Object>> getThBing(HashMap<String,List<String>> depNames) {
        List<HashMap<String,Object>> map = new ArrayList<>();
        HashMap<String, Object> thBing = indexMapper.getThBing(depNames);
        if(thBing!=null){
            HashMap<String, Object> bing = new HashMap<>();
            bing.put("name","退回占比");
            bing.put("value",thBing.get("thzb")==null?0:thBing.get("thzb"));
            map.add(bing);
            HashMap<String, Object> qt = new HashMap<>();
            qt.put("name","其他占比");
            qt.put("value",thBing.get("qtzb")==null?0:thBing.get("qtzb"));
            map.add(qt);
        }else{
            HashMap<String, Object> qt = new HashMap<>();
            qt.put("name","其他占比");
            qt.put("value",100);
            map.add(qt);
        }

        return map;
    }

    @Override
    public HashMap<String, Object> getJrje(List<String> depNames) {
        String[] jeTypes = new String[]{"sqje","msje","thje"};
        String[] sjTypes = new String[]{"sqtfsj","mstfsj","thtfsj"};
        String[] jeNames = new String[]{"今日收取金额","今日没收金额","今日退回金额"};
        HashMap<String,Object> result = new HashMap<>();
        for (int i = 0; i < 3; i++) {
            HashMap<String,Object> jeData = indexMapper.getJeData(jeTypes[i],sjTypes[i],depNames);
            if(jeData!=null){
                result.put(jeNames[i],jeData.get("jrje"));
            }else{
                result.put(jeNames[i],0);
            }
        }
        return result;
    }

    @Override
    public List<HashMap<String, Object>> getSevenDayMsje(HashMap<String,List<String>> depNames) {
        return indexMapper.getSevenDayMsje(depNames);
    }
}
